cmake_minimum_required(VERSION 3.10)

project(simple_gui_demo)

set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN")

# For compiler
# Default use MinGW-w64
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
# SDL2 library path.
set(SDL_DIR D:/Works/dev/libs/SDL/SDL2-2.28.3/x86_64-w64-mingw32)
set(SDL_LIB ${SDL_DIR}/lib)
set(SDL_BIN ${SDL_DIR}/bin)

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    add_compile_options(-g -O0)  # 调试模式：启用调试信息，禁用优化
    set(CEF_LIB ${CEF_DIR}/Debug)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
    add_compile_options(-O3)     # 发布模式：启用最高优化
    set(CEF_LIB ${CEF_DIR}/Release)
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
    add_compile_options(-O2 -g)  # 发布模式，但包含调试信息'
    set(CEF_LIB ${CEF_DIR}/Release)
elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
    add_compile_options(-Os)     # 优化生成的文件大小
    set(CEF_LIB ${CEF_DIR}/Release)
endif()

# C++11
set(CMAKE_CXX_STANDARD 11)

# Header search path.
include_directories(${SDL_DIR}/include/SDL2)
include_directories(${CMAKE_SOURCE_DIR}/GUI/inc)
include_directories(${CMAKE_SOURCE_DIR}/HMI/inc)
include_directories(${CMAKE_SOURCE_DIR}/Simulator/inc)
include_directories(${CMAKE_SOURCE_DIR}/DemoProc/inc)

# Global marco
add_definitions(-DSDL_MAIN_HANDLED)
if(USE_CHS_TEXT)
    include_directories(${CMAKE_SOURCE_DIR}/Library/inc)
    link_directories(${CMAKE_SOURCE_DIR}/Library/lib64)
	add_definitions(-D_SIMPLE_GUI_DEMO_INNER_CHS_)
#   add_definitions(-D_SIMPLE_GUI_ENCODE_TEXT_)
endif()

# Library search path.
link_directories(${SDL_LIB})

# Demo source files.
aux_source_directory(DemoProc DEMO_SRC_LIST)

# SimpleGUI library source.
file(GLOB_RECURSE GUI_LIB_SRC_LIST "GUI/src/*.c")
# Static GUI library.
add_library(simplegui STATIC ${GUI_LIB_SRC_LIST})
# SimpleGUI HMI library source.
file(GLOB_RECURSE HMI_LIB_SRC_LIST "HMI/src/*.c")
# Static HMI library.
add_library(simplegui_hmi STATIC ${HMI_LIB_SRC_LIST})
# SimpleGUI demo source.
file(GLOB_RECURSE DEMO_SRC_LIST "DemoProc/src/*.c")

# Other application source
file(GLOB_RECURSE APP_SRC_LIST "Simulator/src/*.cpp")

# Execution file target.
add_executable(simple_gui_demo ${APP_SRC_LIST} ${DEMO_SRC_LIST})

# Append linkage.
target_link_libraries(simple_gui_demo libSDL2.dll.a)
target_link_libraries(simple_gui_demo simplegui)
target_link_libraries(simple_gui_demo simplegui_hmi)
if(USE_CHS_TEXT)
    target_link_libraries(simple_gui_demo libiconv64.a)
endif()

# Copy runtime needed.
file(COPY ${SDL_BIN}/SDL2.dll DESTINATION ${CMAKE_BINARY_DIR})
